package com.example.text.ui.mall.viewmodel

import android.os.Handler
import android.os.Looper
import androidx.lifecycle.MutableLiveData
import com.example.text.ui.mall.model.CommonPageModel
import com.example.text.ui.mall.model.MallGoods
import com.example.text.ui.mall.repository.MallRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
 * Created by ZengCS on 2023/3/17.
 * E-mail:zengcs@vip.qq.com
 * Add:中国成都
 * Desc: 商品相关ViewModel
 */
@HiltViewModel
class MallGoodsViewModel @Inject constructor(
    private val mRepository: MallRepository
) : BaseMallViewModel(mRepository) {

//    fun pageSeckillList(page: Int) {
//        // 模拟请求接口获取数据
//        Handler(Looper.getMainLooper()).postDelayed({
//            seckillResultLiveData.postValue(MallDataProvider.mockGoodsList(page, ifSeckill = true))
//        }, 600)
//    }

//    fun pageGoodsList(page: Int) {
//        // 模拟请求接口获取数据
//        Handler(Looper.getMainLooper()).postDelayed({
//            goodsResultLiveData.postValue(MallDataProvider.mockGoodsList(page, ifSeckill = false))
//        }, 600)
//    }

    val goodsPageData by lazy {
        MutableLiveData<CommonPageModel<MallGoods>>()
    }

//    fun pageGoodsList(typeId: String, page: Int, pageSize: Int) {
//        execute(action = mRepository.pageGoods(typeId, page, pageSize), onStart = { if (page == 1) _stateListener.emit(Loading) }, onFinished = {
//            goodsPageData.postValue(it.data)
//            _stateListener.emit(Success)
//        }, onError = {
//            // _stateListener.emit(Failed(it))
//
//            val mockPage = CommonPageModel(
//                current = page, pages = 3, size = pageSize, records = MallDataProvider.mockGoodsList(page), total = pageSize * 3
//            )
//            goodsPageData.postValue(mockPage)
//            _stateListener.emit(Success)
//        })
//    }

//    /**增加商品足迹*/
//    fun addGoodsFootPrint(goodsId: Long?, imageResourceId: Long?) {
//        val body = CommonSimpleBody(id = goodsId, resourceId = imageResourceId)
//        executeOpenApi(action = mRepository.addGoodsFootPrint(body))
//    }
}